<?php

namespace App\Http\Controllers\API;

use App\Criteria\DateTimeCriteria;
use App\Repositories\LogRepository;
use Illuminate\Http\Request;
use App\Http\Controllers\AppBaseController;
use InfyOm\Generator\Criteria\LimitOffsetCriteria;
use Prettus\Repository\Criteria\RequestCriteria;

class LogAPIController extends AppBaseController
{
    private  $logRepository;
    public function __construct(LogRepository $logRepository)
    {
        $this->logRepository = $logRepository;
    }

    /**
     * Display a listing of the Device.
     * GET|HEAD /devices
     *
     * @param Request $request
     * @return Response
     */
    public function index(Request $request)
    {
        $this->validate($request,['start_time'=>'date','end_time'=>'date']);
        $this->logRepository->pushCriteria(new RequestCriteria($request));
        $this->logRepository->pushCriteria(DateTimeCriteria::class);
        $this->logRepository->pushCriteria(new LimitOffsetCriteria($request));
        $logs = $this->logRepository->paginate($request->limit);
        return $this->sendResponse($logs->toArray(), 'Devices retrieved successfully');
    }

}
